package com.kaizeli.website.controller;

import com.kaizeli.website.pojo.entity.EmployeeAcceptance;
import com.kaizeli.website.pojo.dto.EmployeeAcceptanceDTO;
import com.kaizeli.website.response.Result;
import com.kaizeli.website.service.EmployeeAcceptanceService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * 人员验收控制器
 */
@Tag(name = "人员验收管理", description = "人员验收相关接口")
@RestController
@RequestMapping("/api/employee-acceptance")
public class EmployeeAcceptanceController {

    @Autowired
    private EmployeeAcceptanceService employeeAcceptanceService;

    @Operation(summary = "根据验收节点ID查询人员验收列表")
    @GetMapping("/acceptance/{acceptanceId}")
    public Result<List<EmployeeAcceptanceDTO>> getEmployeeAcceptancesByAcceptanceId(
            @Parameter(description = "验收节点ID") @PathVariable Long acceptanceId) {
        return employeeAcceptanceService.getEmployeeAcceptancesByAcceptanceId(acceptanceId);
    }

    @Operation(summary = "根据项目ID查询人员验收列表")
    @GetMapping("/project/{projectId}")
    public Result<List<EmployeeAcceptanceDTO>> getEmployeeAcceptancesByProjectId(
            @Parameter(description = "项目ID") @PathVariable Long projectId) {
        return employeeAcceptanceService.getEmployeeAcceptancesByProjectId(projectId);
    }

    @Operation(summary = "根据员工ID查询人员验收列表")
    @GetMapping("/employee/{employeeId}")
    public Result<List<EmployeeAcceptanceDTO>> getEmployeeAcceptancesByEmployeeId(
            @Parameter(description = "员工ID") @PathVariable Long employeeId) {
        return employeeAcceptanceService.getEmployeeAcceptancesByEmployeeId(employeeId);
    }

    @Operation(summary = "创建人员验收记录")
    @PostMapping
    public Result<EmployeeAcceptance> createEmployeeAcceptance(@RequestBody EmployeeAcceptance employeeAcceptance) {
        return employeeAcceptanceService.createEmployeeAcceptance(employeeAcceptance);
    }

    @Operation(summary = "更新人员验收记录")
    @PutMapping("/{id}")
    public Result<EmployeeAcceptance> updateEmployeeAcceptance(
            @Parameter(description = "人员验收记录ID") @PathVariable Long id,
            @RequestBody EmployeeAcceptance employeeAcceptance) {
        employeeAcceptance.setId(id);
        return employeeAcceptanceService.updateEmployeeAcceptance(employeeAcceptance);
    }

    @Operation(summary = "计算验收节点总工时")
    @GetMapping("/acceptance/{acceptanceId}/total-work-hours")
    public Result<BigDecimal> calculateTotalWorkHours(
            @Parameter(description = "验收节点ID") @PathVariable Long acceptanceId) {
        return employeeAcceptanceService.calculateTotalWorkHours(acceptanceId);
    }

    @Operation(summary = "计算验收节点总人工费用")
    @GetMapping("/acceptance/{acceptanceId}/total-labor-cost")
    public Result<BigDecimal> calculateTotalLaborCost(
            @Parameter(description = "验收节点ID") @PathVariable Long acceptanceId) {
        return employeeAcceptanceService.calculateTotalLaborCost(acceptanceId);
    }

    @Operation(summary = "批量创建人员验收记录")
    @PostMapping("/batch")
    public Result<Void> batchCreateEmployeeAcceptances(@RequestBody List<EmployeeAcceptance> employeeAcceptances) {
        return employeeAcceptanceService.batchCreateEmployeeAcceptances(employeeAcceptances);
    }
}
